Ext.define("Demo.view.base.advanceBar", {
	extend : "Ext.toolbar.Paging",
	alias : "widget.advanceBar",
	displayInfo:true,
	displayMsg:'显示{0} - {1}/{2}',
	emptyMsg:"当前单据没有数据",
	listeners:{
		afterrender:function(cmp,opts){
		},
		activate:function(){
			alert(11);
		}
	},
	items : [ {
		text : '新增',
		icon : "/fam/add.gif",
		handler : function(btn) {
			var panel = Ext.getCmp("mainTabs");
			var a = panel.getActiveTab().title.indexOf('(');
			panel.getActiveTab().setTitle(panel.getActiveTab().title.substring(0,a)+'(新增...)');
			var activeTab = panel.getActiveTab();//获取当前活动窗口
			var downPanel = activeTab.down("panel");//获取活动窗口下的panel
			var downForm = activeTab.down('form');
			setFormReadOnly(downForm,false);
		}
	}, 
	{
		text: '保存',
		icon : "/fam/add.gif",
		handler : function(btn) {
			var panel = Ext.getCmp("mainTabs");
			var activeTab = panel.getActiveTab();//获取当前活动窗口
			var downPanel = activeTab.down("panel");//获取活动窗口下的panel
			var downForm = activeTab.down('form');//获取活动窗口下的form
			var datas = downForm.getForm().getValues();//获取form下的所有值
			var grid = Ext.pluck(activeTab.down('grid').getStore().data.items,'data');//grid中所有的数据 
			Ext.each(grid,function(item){
				item.billNo = datas.billNo; //循环给详表billNo复制
			});
			datas.details = grid; // 主详绑定   xml循环的的对象时 map.details 注意
			alert(JSON.stringify(datas));//主详数据
			
			Ext.Ajax.request({
			    url: "advance/addAdvance",
			    method: 'POST',
			    params: JSON.stringify(datas),
			    headers: {
			    	'Content-Type':'application/json'
			    },
			    success: function(response){
			        var text = response.responseText;
			        alert(JSON.stringify(text));
			    },
			    failure: function (response, options) {
                    Ext.MessageBox.alert('失败', '请求超时或网络故障,错误编号：' + response.status);
                }
			});
		}
			
	},{
		text : '修改',
		icon : "/fam/add.gif",
		handler : function(btn) {
			var panel = Ext.getCmp("mainTabs");
			var a = panel.getActiveTab().title.indexOf('(');
			panel.getActiveTab().setTitle(panel.getActiveTab().title.substring(0,a)+'(新增...)');
			var activeTab = panel.getActiveTab();//获取当前活动窗口
			var downPanel = activeTab.down("panel");//获取活动窗口下的panel
			var downForm = activeTab.down('form');
			setFormReadOnly(downForm,false);
		}
	},{
		text : '修改保存',
		//icon : "/fam/add.gif",
		handler : function(btn) {
			var panel = Ext.getCmp("mainTabs");
			var activeTab = panel.getActiveTab();//获取当前活动窗口
			var downPanel = activeTab.down("panel");//获取活动窗口下的panel
			var downForm = activeTab.down('form');//获取活动窗口下的form
			var datas = downForm.getForm().getValues();//获取form下的所有值
			var grid = Ext.pluck(activeTab.down('grid').getStore().data.items,'data');//grid中所有的数据 
			Ext.each(grid,function(item){
				item.billNo = datas.billNo; //循环给详表billNo复制
			});
			datas.details = grid; // 主详绑定   xml循环的的对象时 map.details 注意
			alert(JSON.stringify(datas));//主详数据
			
			Ext.Ajax.request({
			    url: "advance/updateAdvance",
			    method: 'POST',
			    params: JSON.stringify(datas),
			    headers: {
			    	'Content-Type':'application/json'
			    },
			    success: function(response){
			        var text = response.responseText;
			        alert(JSON.stringify(text));
			    },
			    failure: function (response, options) {
                    Ext.MessageBox.alert('失败', '请求超时或网络故障,错误编号：' + response.status);
                }
			});
		}
	},  
	{
		text: '放弃',
		handler : function(btn) {
			var panel = Ext.getCmp("mainTabs");
			var activeTab = panel.getActiveTab();//获取当前活动窗口
			var downForm = activeTab.down('form');
			setFormReadOnly(downForm,true);
		}
	},
	{
		text: '删除',
		icon : "/fam/delete.gif",
		handler : function(btn) {
			var panel = Ext.getCmp("mainTabs");
			var activeTab = panel.getActiveTab();//获取当前活动窗口
			var downPanel = activeTab.down("panel");
			var downForm = activeTab.down('form');//获取活动窗口下的form
			var datas = downForm.getForm().getValues();//获取form下的所有值
			alert(JSON.stringify(datas));
			Ext.MessageBox.confirm('Confirm', '确认删除记录项吗?',function(btn){
				if(btn == "yes"){
					Ext.Ajax.request({
					    url: "advance/deleteAdvance",
					    method: 'POST',
					    params: JSON.stringify(datas),
					    headers: {
					    	'Content-Type':'application/json'
					    },
					    success: function(response){
					        var text = response.responseText;
					        alert(JSON.stringify(text));
					    },
					    failure: function (response, options) {
				            Ext.MessageBox.alert('失败', '请求超时或网络故障,错误编号：' + response.status);
				        }
					});
				}
				//	methodPost(panel.getActiveTab().id,'updLogicalState',datas); //删除(逻辑删除)
			});

			
		}
	},
	{
		text: '审核',
		icon : "/fam/cog.png",
		handler : function(btn) {
			//Ext.getCmp("autidStatus")
			var panel = Ext.getCmp("mainTabs");
			var activeTab = panel.getActiveTab();//获取当前活动窗口
			var downPanel = activeTab.down("panel");
			var downForm = activeTab.down('form');//获取活动窗口下的form
			var datas = downForm.getForm().getValues();//获取form下的所有值
			datas.autidStatus=1;
			alert(JSON.stringify(datas));
			Ext.MessageBox.confirm('Confirm', '确认审核记录项吗?',function(btn){
				if(btn == "yes"){
					Ext.Ajax.request({
					    url: "advance/updatePermitter",
					    method: 'POST',
					    params: JSON.stringify(datas),
					    headers: {
					    	'Content-Type':'application/json'
					    },
					    success: function(response){
					        var text = response.responseText;
					        alert(JSON.stringify(text));
					        alert("审核成功！");
					        
					    },
					    failure: function (response, options) {
				            Ext.MessageBox.alert('失败', '请求超时或网络故障,错误编号：' + response.status);
				        }
					});
				}
			});

			
		}
	},{
		text: '取消审核',
		icon : "/fam/cross.gif",
		handler : function(btn) {
			var panel = Ext.getCmp("mainTabs");
			var activeTab = panel.getActiveTab();//获取当前活动窗口
			var downPanel = activeTab.down("panel");
			var downForm = activeTab.down('form');//获取活动窗口下的form
			var datas = downForm.getForm().getValues();//获取form下的所有值
			alert(JSON.stringify(datas));
			datas.autidStatus=0;
			Ext.MessageBox.confirm('Confirm', '确认审核记录项吗?',function(btn){
				if(btn == "yes"){
					Ext.Ajax.request({
					    url: "advance/updatePermitter",
					    method: 'POST',
					    params: JSON.stringify(datas),
					    headers: {
					    	'Content-Type':'application/json'
					    },
					    success: function(response){
					        var text = response.responseText;
					        alert(JSON.stringify(text));
					    },
					    failure: function (response, options) {
				            Ext.MessageBox.alert('失败', '请求超时或网络故障,错误编号：' + response.status);
				        }
					});
				}
			});

			
		}
	},
	{
		text : '事实上',
		icon : "/fam/add.gif",
		listeners:{
			click:function(btn){
				this.abc;
			},
			mouseover:function(){
//				alert(12222);
			}
		}
	}, {
		xtype : 'splitbutton',
		text : '分割按钮'
	},
	// 使用右对齐容器
	'->', // 等同 { xtype: 'tbfill' }
	{
		xtype : 'textfield',
		name : 'field1',
		emptyText : '输入搜索词'
	},
	// 添加工具栏项之间的垂直分隔条
	'-', // 等同 {xtype: 'tbseparator'} 创建 Ext.toolbar.Separator
	'text 1', // 等同 {xtype: 'tbtext', text: 'text1'} 创建 Ext.toolbar.TextItem
	{
		xtype : 'tbspacer'
	},// 等同 ' ' 创建 Ext.toolbar.Spacer
	'text 2', {
		xtype : 'tbspacer',
		width : 50
	}, // 添加一个50像素的空格
	'text 3' ]
});

